package com.wteam.controller;


import com.wteam.PoJo.DO.Postwork;
import com.wteam.PoJo.DTO.CommentDTO;
import com.wteam.PoJo.DTO.PageQuery;
import com.wteam.PoJo.DTO.PostworkDTO;
import com.wteam.PoJo.DTO.ReplyCommentDTO;
import com.wteam.PoJo.VO.PostworkVO;
import com.wteam.PoJo.VO.ReplyCommentVO;
import com.wteam.Service.IPostworkService;
import com.wteam.until.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 帖子表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-07-16
 */
@RestController
@Api(tags = "帖子模块")
@RequestMapping("/postwork")
public class PostworkController {
    @Autowired
    private IPostworkService iPostworkService;

    @PutMapping("/addpostwork")
    @ApiOperation("发布帖子")
    @Transactional(rollbackFor = Exception.class)
    public Result addpostwork(@RequestBody PostworkDTO postworkDTO) {
        return iPostworkService.buyorder(postworkDTO);
    }

    @PutMapping("/postwork")
    @ApiOperation("发现查看所有帖子")
    public Result<List<PostworkVO>> viewpostwork(@RequestBody PageQuery pageQuery) {
        return iPostworkService.viewpostwork(pageQuery);
    }



    @GetMapping("/postwork/{parentId}")
    @ApiOperation("根据帖子id查帖子详情）")
    public Result<PostworkVO> postworkbyId(@ApiParam("帖子id")@PathVariable Long parentId) {
        return iPostworkService.postworkbyId(parentId);
    }

    @PutMapping("/mypostwork")
    @ApiOperation("查看我发布的帖子")
    public Result<List<PostworkVO>> viewmypostwork(@RequestBody PageQuery pageQuery) {
        return iPostworkService.viewmypostwork(pageQuery);
    }

    @DeleteMapping("/mypostwork/{parentId}")
    @ApiOperation("删除我发布的帖子")
    public Result deletemypostwork(@PathVariable@ApiParam("帖子id") Long parentId) {
        return iPostworkService.deletemypostwork(parentId);
    }
    @PutMapping("/followpostwork")
    @ApiOperation("查看关注的人的帖子")
    public Result<List<PostworkVO>> followpostwork(@RequestBody PageQuery pageQuery) {
        return iPostworkService.followpostwork(pageQuery);
    }

}
